package com.fpt.edu.vn.h2tv.api.staff;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.OPTIONS;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.fpt.edu.vn.h2tv.service.UserService;

@Path("/manageCustomer")
public class CustomerAdminAPI {
    
    @GET
    @Produces(javax.ws.rs.core.MediaType.APPLICATION_XML)    
    public Response manageCustomer(){
        
        return buildResponse(MediaType.APPLICATION_XML, UserService.getAllCustomer());
    }
    
    @Path("/searchCustomer")
    @GET
    @Produces(javax.ws.rs.core.MediaType.APPLICATION_XML)    
    public Response searchStaff(@QueryParam(value="txtUserName") String username){
        
        return buildResponse(MediaType.APPLICATION_XML, UserService.searchCustomer(username));
    }
    
    @DELETE
    @Produces(javax.ws.rs.core.MediaType.TEXT_HTML)
    public Response deleteCustomer(@QueryParam(value="txtCusId") Long id){
        
        return buildResponse(MediaType.TEXT_HTML, UserService.deleteAccount(id));
    }
    
    @PUT
    @Produces(javax.ws.rs.core.MediaType.TEXT_HTML)
    public Response updateCustomer(@QueryParam(value="txtCusId") Long id,@QueryParam(value="txtUpdateCusIsBan") Boolean ban){
        
        return buildResponse(MediaType.TEXT_HTML, UserService.updateCus(id, ban));
    }
    
    @OPTIONS
    @Produces(javax.ws.rs.core.MediaType.TEXT_HTML)
    public Response test(){
            
        return buildResponse(MediaType.TEXT_HTML, "ok");
    }
    
    private Response buildResponse(String mediaType, Object repsonse){
        return Response.ok(repsonse, mediaType)
//                .header("Access-Control-Allow-Origin", "http://localhost")
//                .header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS,TRACE,HEAD,CONNECT")
//                .header("Access-Control-Allow-Credentials",true)
//                .header("Access-Control-Allow-Headers", "x-accept-charset, x-accept, origin,X-Accept-Charset,X-Accept,Content-Type,Authorization,REFERER")
                .build();
    }
    
    
}
